import { NoSkinCellRenderer } from "../../common/item/NoSkinCellRenderer";
import { SCrossGuildWarMatchInfo } from "../../../../../Message/Public/SCrossGuildWarMatchInfo";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { DateUtil } from "../../../../common/tools/DateUtil";
import { ClockManager } from "../../../manager/ClockManager";
import { CrossGuildWarUtil } from "../util/CrossGuildWarUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { SecTimerView } from "../../common/SecTimerView";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class CrossGuildWarScheduleLiveRender
    
    export  class CrossGuildWarScheduleLiveRender extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            if (arg1 == null) 
            {
                return;
            }
            super.data = arg1;
            this._myData = arg1 as SCrossGuildWarMatchInfo;
            if (this._myData == null) 
            {
                return;
            }
            this._txtGuild1.text = this._myData.guildName1;
            if (this._myData.guildName1 == "") 
            {
                this._txtGuild1.text = Language.getString(80565);
            }
            this._txtGuild2.text = this._myData.guildName2;
            if (this._myData.guildName2 == "") 
            {
                this._txtGuild2.text = Language.getString(80565);
            }
            if (this._myData.isEnd) 
            {
                if (this._bmpWin == null) 
                {
                    this._bmpWin = ObjCreate.createBitmap(ImagesConst.CrossGuildWar_win, 55, 3, this);
                }
                if (this._bmpLost == null) 
                {
                    this._bmpLost = ObjCreate.createBitmap(ImagesConst.CrossGuildWar_lost, 456, 3, this);
                }
                this.addChild(this._bmpWin);
                this.addChild(this._bmpLost);
                if (this._leftTime.running) 
                {
                    this._leftTime.stop();
                }
                this._leftTime.htmlText = "<font color=\'#ff0000\'>" + Language.getString(44273) + "</font>";
                this._watchBtn.visible = false;
            }
            else 
            {
                DisplayUtil.removeMe(this._bmpWin);
                DisplayUtil.removeMe(this._bmpLost);
                this._leftTime.setParse("<font color=\'#ff0000\'>mm: ss</font>");
                this._leftTime.setLeftTime(DateUtil.getSecondsDis(ClockManager.instance.nowDate, this._myData.ringEndDt, true));
                this._watchBtn.visible = true;
            }
            if (CrossGuildWarUtil.isOurGuild(this._myData.guildName1, this._myData.guildId1.id) || CrossGuildWarUtil.isOurGuild(this._myData.guildName2, this._myData.guildId2.id)) 
            {
                if (this._selectedBg == null) 
                {
                    this._selectedBg = ObjCreate.createBg(0, 0, 788, 42, null, ImagesConst.SelectedBg);
                }
                this.addChildAt(this._selectedBg, 0);
            }
            else 
            {
                DisplayUtil.removeMe(this._selectedBg);
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(10, 42, 785, 2, this, ImagesConst.SplitLine);
            var loc1=GlobalStyle.textFormat1;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtGuild1 = ObjCreate.createGTextField("", 0, 11, 300, 20, this, loc1);
            ObjCreate.createBitmap(ImagesConst.ArenaVS, 315, 1, this);
            loc1 = GlobalStyle.textFormat1;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtGuild2 = ObjCreate.createGTextField("", 377, 11, 359, 20, this, loc1);
            this._leftTime = ObjCreate.createSecTimeView("<font color=\'#ff0000\'>mm: ss</font>", 697, 11, 120, 20, this);
            this._watchBtn = ObjCreate.createGButton(Language.getString(44209), 740, 10, 49, 22, this);
            this._watchBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onWatchBtnClickHandler);
            this._watchBtn.drawNow();
            return;
        }

        /* internal  */onWatchBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGuildWarWatchGuildWar, this._myData));
            return;
        }

        /* internal */ /* var */_txtGuild1: GTextFiled;

        /* internal */ /* var */_txtGuild2: GTextFiled;

        /* internal */ /* var */_leftTime: SecTimerView;

        /* internal */ /* var */_bmpWin: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpLost: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_selectedBg: ScaleBitmap;

        /* internal */ /* var */_watchBtn: GButton;

        /* internal */ /* var */_myData: SCrossGuildWarMatchInfo;
    }
